<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../layuimini/lib/layui-v2.6.3/css/layui.css" media="all">
    <script src="../../layuimini/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
    <link rel="stylesheet" href="../../layuimini/css/public.css" media="all">
    <script src="../../layuimini/js/lay-config.js?v=1.0.4" charset="utf-8"></script>
    <style>
        body {
            background-color: #ffffff;
        }
        /*#box{*/
        /*    margin-left: 25px;*/
        /*    margin-top: 25px;*/
        /*    width: 500px;*/
        /*    height: 450px;*/
        /*    box-shadow: 0 0 3px #ccc;*/
        /*}*/
        /*#box-form{*/
        /*    height: 400px;*/
        /*    margin: 0 auto;*/
        /*    width: 350px;*/
        /*    padding-top: 25px;*/
        /*}*/
    </style>
</head>
<body>
<div id="box">
    <form id="box-form" class="layui-form" action="" th:object="${custom}">


        <div class="layui-form-item">
            <label class="layui-form-label">客户编号</label>
            <div class="layui-input-inline">
                <input disabled  type="text" name="number" required th:field="*{tNumber}"  lay-verify="required" placeholder="请输入名称" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item" style="display: none">
            <label class="layui-form-label">地区编号</label>
            <div class="layui-input-inline">
                <input hidden type="text" name="areaId" required th:field="*{tAreaId}"   lay-verify="required" placeholder="请输入名称" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">客户名称</label>
            <div class="layui-input-inline">
                <input type="text" name="name" required th:field="*{tName}" lay-verify="required" placeholder="请输入名称" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">客户电话</label>
            <div class="layui-input-inline">
                <input type="text" name="phone" required th:field="*{tPhone}" lay-verify="required" placeholder="请输入电话" autocomplete="off" class="layui-input">
            </div>
        </div>

        <!-- 地区选择 -->
        <div class="layui-form-item" id="area-picker">
            <div class="layui-form-label">户籍所在地</div>
            <div class="layui-input-inline" style="width: 200px;">
                <select name="province" class="province-selector" th:data-value="${area.tProvince}" lay-filter="province-1">
                    <option value="">请选择省</option>
                </select>
            </div>
            <div class="layui-input-inline" style="width: 200px;">
                <select name="city" class="city-selector" th:data-value="${area.tCity}" lay-filter="city-1">
                    <option value="">请选择市</option>
                </select>
            </div>
            <div class="layui-input-inline" style="width: 200px;">
                <select name="county" class="county-selector" th:data-value="${area.tCounty}" lay-filter="county-1">
                    <option value="">请选择 县/区</option>
                </select>
            </div>
        </div>

        <div class="layui-form-item" style="width: 50%">
            <label class="layui-form-label">详细地址</label>
            <div class="layui-input-block">
                <input type="text" name="detailed" th:value="${area.tDetailed}" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item" style="width: 25%;">
            <label class="layui-form-label">会员等级</label>
            <div class="layui-input-block">
                <select th:field="*{tMemberId}" name="memberId" lay-verify="required">
                    <option value="">请选择</option>
                    <option th:each="member:${memberList}" th:value="${member.tId}">
                        <span th:text="${member.tDescribe}"></span>
                    </option>
                </select>
            </div>
        </div>


        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-normal" id="btn-edit" lay-submit lay-filter="formDemo">修改</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>

<script>
    layui.use(['layer' , 'form' , 'layarea' ], function(){
        var form = layui.form,
            layarea = layui.layarea,
            layer = layui.layer;
        var $ = layui.$;

        //地区选择控件
        layarea.render({
            elem: '#area-picker',
        });

        //监听提交
        form.on('submit(formDemo)', function(data){
            $("#btn-edit").attr("disabled","disabled").addClass("layui-btn-disabled");
            data = data.field;
            //异步发送修改请求
            $.post("/custom/updateCustom",data,function (res){
                if(res.code == 0){
                    layer.msg('修改成功!',{time: 1000, icon: 1},function (){
                        //刷新表格
                        parent.refreshTable();
                        //关闭窗口
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                    });
                }else{
                    $("#btn-edit").removeAttr("disabled","disabled").removeClass("layui-bth-disabled");
                    layer.msg('修改失败',{time: 1000, icon: 4});
                }
            });
            return false;
        });
    });
</script>
</body>
</html>